<#include "/layout/header.ftl" />
<#import "/include/ui.ftl" as blue />

<script src="${rc_path}/js/jquery/jquery-treetable.js"></script>
<script>

$(function()
{
	<#if model.type??>
	$("#slt_type").val("${model.type}");
	</#if>
	type_change();
});

function type_change()
{
	var type = $("#slt_type").val();
	if (type == "view")
	{
		$("#div_url").show();
		$("#txt_url").attr("required", "required");
		$("#div_key").hide();
		$("#txt_key").removeAttr("required");
	}
	else if (type == "click")
	{
		$("#div_url").hide();
		$("#txt_url").removeAttr("required");
		$("#div_key").show();
		$("#txt_key").attr("required", "required");
	}
}

function save_click()
{
	$.simpleValid("#div_form", function(obj)
	{
		$.simpleAjax("/base/wechat/wechat_menu_save", obj, function(o)
		{
			$.successAlert("保存成功", "save_success()", 2000);
		});
	});
}
function save_success()
{
	window.location = "${path}/base/wechat/wechat_menu_list?wechatId=${(wechat.id)!}";
}

function tree_onselect(id, parentId, name)
{
	$("#hdn_parent_menu_id").val(id);
	$("#btn_select_parent_menu").text(name);
}

function tree_onunselect()
{
	$("#hdn_parent_menu_id").val("");
	$("#btn_select_parent_menu").text("选择上级菜单");
}

</script>

<div class="am-form am-form-horizontal layout-padding-content" id="div_form">
<input type="hidden" name="id" value="${model.id!}"/>

	<fieldset>
		<legend><#if model.id??>修改<#else>添加</#if>菜单</legend>

		<div class="am-u-md-6">
			<div class="am-form-group">
				<label class="am-u-md-2 am-form-label am-padding-left-0 am-padding-right-0">微信</label>
				<div class="am-u-md-9 am-u-end">
					<select class="am-form-field am-radius" name="wechatId" data-am-selected="{'btnWidth': '200px'}" required>
					<@blue.select list=wechatList value=(model.wechatId)!"0" />
					</select>
				</div>
			</div>
		</div>

		<div class="am-u-md-6">
			<div class="am-form-group">
				<label class="am-u-md-2 am-form-label am-padding-left-0 am-padding-right-0">上级菜单</label>
				<div class="am-u-md-9 am-u-end">
					<input type="hidden" id="hdn_parent_menu_id" name="parentId" />
					<a href="javascript:void(0)" id="btn_select_parent_menu" class="am-btn am-btn-default am-radius" data-am-modal="{target: '#div_model'}">${model.parentName!"选择上级菜单"}</a>
				</div>
			</div>
		</div>
		
		<div class="am-u-md-6">
			<div class="am-form-group">
				<label class="am-u-md-2 am-form-label am-padding-left-0 am-padding-right-0">名称</label>
				<div class="am-u-md-9 am-u-end">
					<input type="text" name="name" placeholder="输入菜单名称" class="am-form-field am-radius"  maxlength="20" value="${model.name!}" required/>
				</div>
			</div>
		</div>

		<div class="am-u-md-6">
			<div class="am-form-group">
				<label class="am-u-md-2 am-form-label am-padding-left-0 am-padding-right-0">类型</label>
				<div class="am-u-md-9 am-u-end">
					<select class="am-form-field am-radius" id="slt_type" name="type" data-am-selected="{'btnWidth': '120px'}" required onchange="type_change()">
						<option value="view">view</option>
						<option value="click">click</option>
					</select>
				</div>
			</div>
		</div>
		
		<div class="am-u-md-12" id="div_key">
			<div class="am-form-group">
				<label class="am-u-md-1 am-form-label am-padding-left-0 am-padding-right-0">键</label>
				<div class="am-u-md-10 am-u-end">
					<input type="text" id="txt_key" name="key" placeholder="输入键" class="am-form-field am-radius"  maxlength="50" value="${model.key!}" />
				</div>
			</div>
		</div>
		
		<div class="am-u-md-12" id="div_url">
			<div class="am-form-group">
				<label class="am-u-md-1 am-form-label am-padding-left-0 am-padding-right-0">URL</label>
				<div class="am-u-md-10 am-u-end">
					<input type="text" id="txt_url" name="url" placeholder="输入URL" class="am-form-field am-radius"  maxlength="200" value="${model.url!}" />
				</div>
			</div>
		</div>

		<div class="am-u-md-6">
			<div class="am-form-group">
				<label class="am-u-md-2 am-form-label am-padding-left-0 am-padding-right-0">状态</label>
				<div class="am-u-md-9 am-u-end">
					<select class="am-form-field am-radius" name="state" data-am-selected="{'btnWidth': '120px'}" required>
						<@blue.select list=map.state value=(model.state.index)!"0" />
					</select>
				</div>
			</div>
		</div>
		
		<div class="am-u-md-6">
			<div class="am-form-group">
				<label class="am-u-md-2 am-form-label am-padding-left-0 am-padding-right-0">排序</label>
				<div class="am-u-md-9 am-u-end">
					<input type="number" name="sort" placeholder="输入菜单排序" class="am-form-field am-radius"  maxlength="10" value="${model.sort!"0"}" required/>
				</div>
			</div>
		</div>
		
		<div class="am-u-md-12">
			<div class="am-form-group">
				<label class="am-u-md-1 am-form-label am-padding-left-0 am-padding-right-0">描述</label>
				<div class="am-u-md-10 am-u-end">
					<textarea name="descp" placeholder="输入菜单描述" class="am-form-field am-radius" style="height: 300px;"
						maxlength="200">${model.descp!}</textarea>
				</div>
			</div>
		</div>

		<div class="am-u-md-12 am-text-center div_btn">
			<a href="javascript:void(0)" onclick="save_click()" class="am-btn am-btn-primary am-radius">保存</a>
			<a href="javascript:void(0)" onclick="save_success()" class="am-btn am-btn-default am-radius am-margin-left">返回</a>
		</div>
	</fieldset>
</div>

<#include "/include/tree_dialog.ftl" />
<#include "/layout/footer.ftl" />